package com.tools.security.utils;

import org.springframework.lang.NonNull;
import org.springframework.util.Assert;

public class SecurityCacheKeyUtils {
    private final static String USER_ACCESS_TOKEN_CACHE_PREFIX = "admin.access.token.with.user.";
    private final static String USER_REFRESH_TOKEN_CACHE_PREFIX = "admin.refresh.token.with.user.";
    private final static String ACCESS_TOKEN_CACHE_PREFIX = "admin.access_token.";
    private final static String REFRESH_TOKEN_CACHE_PREFIX = "admin.refresh_token.";
    private final static String USER_CAPTCHA = "user.captcha.";
    private final static String USER_LOGIN_FAIL = "user.login.fail.";

    private SecurityCacheKeyUtils() {
    }

    @NonNull
    public static String buildUserIdAccessTokenKey(@NonNull String userId) {
        Assert.hasText(userId, "userId must not be null");
        return USER_ACCESS_TOKEN_CACHE_PREFIX + userId;
    }

    @NonNull
    public static String buildUserIdRefreshTokenKey(@NonNull String userId) {
        Assert.hasText(userId, "userId must not be null");
        return USER_REFRESH_TOKEN_CACHE_PREFIX + userId;
    }

    @NonNull
    public static String buildAccessTokenUserIdKey(@NonNull String accessToken) {
        Assert.hasText(accessToken, "Access token must not be blank");
        return ACCESS_TOKEN_CACHE_PREFIX + accessToken;
    }

    @NonNull
    public static String buildRefreshTokenUserIdKey(@NonNull String refreshToken) {
        Assert.hasText(refreshToken, "Refresh token must not be blank");
        return REFRESH_TOKEN_CACHE_PREFIX + refreshToken;
    }

    @NonNull
    public static String buildUserIdCaptcha(@NonNull String userName) {
        Assert.hasText(userName, "userName must not be blank");
        return USER_CAPTCHA + userName;
    }

    @NonNull
    public static String buildUserIdLoginFailTimes(@NonNull String userName) {
        Assert.hasText(userName, "userName must not be blank");
        return USER_LOGIN_FAIL + userName;
    }
}
